package com.ls.fw.imgserver.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ls.fw.imgserver.exception.ImageOperateException;
import com.ls.fw.imgserver.handler.RequestHandler;
import com.ls.fw.imgserver.handler.RequestHandlerImpl;
import com.ls.fw.web.core.servlet.BaseServlet.SubmitType;
import com.ls.fw.web.core.servlet.bean.ValidResult;
import com.ls.fw.web.file.down.BaseDown;
import com.ls.fw.web.file.servlet.BaseFileServlet;

public class FileServlet extends BaseFileServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private RequestHandler handl = null;
	
	@Override
	public void init() throws ServletException {
		super.init();
		String _baseDir = this.getInitParameter(BaseDown.BASEDIR);
		String _isAbsolutePath = this.getInitParameter(BaseDown.ISABSOLUTEPATH);
		this.handlPara(_baseDir,_isAbsolutePath);
		handl = new RequestHandlerImpl(contextDir,this.baseDir,isAbsolutePath);
		this.log("初始化请求处理器完成！");
	}

	@Override
	protected void illegalRequest(ValidResult validResult,
			HttpServletRequest request, HttpServletResponse response,
			Object... paras) {
		 
		
	}

	@Override
	protected void exceptionCaught(HttpServletRequest request,
			HttpServletResponse response, Object result, Throwable throwable) {
		 
		
	}

	@Override
	protected void handlRequest(SubmitType submitType,
			HttpServletRequest request, HttpServletResponse response) throws ImageOperateException, ServletException, IOException {
//		String dir = request.getParameter("dir");
//		if(this.isEmpty(dir)){
//			dir = File.separator;
//		}
//		String filter = request.getParameter("filter"); 
//		String all = request.getParameter("all"); 
//		String baseDir = "";
//		dir  = baseDir + dir;
//		File f = new File(dir);
//	    if (f.exists() && f.isDirectory()){
//	        int count = f.list(new FilenameFilter(){
//	            @Override
//	            public boolean accept(File dir, String name) {
//	                System.out.println(dir.getPath()+"\\"+name);
//	            	if (name.endsWith(".txt") || name.endsWith(".bat") || name.endsWith(".java"))
//	                    return true;
//	                 
//	                return false;
//	            }
//	        }).length;
//	    }
	    this.handl.handl(submitType, request, response);
	}

	@Override
	protected boolean isLegalRequest(HttpServletRequest request) {
		return false;
	}

}
